package uk.co.cocking.getinline2.pipeline.io;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;

public class LineReader {
	private final Reader reader;

	public LineReader(Reader reader) {
		this.reader = reader;
	}
	
	public List<String> lines() throws CouldNotProcessRecordException {
		BufferedReader in = new BufferedReader(reader);
		List<String> lines = new ArrayList<String>();
		String line;
		try {
			while ((line = in.readLine()) != null) {
				lines.add(line);
			}
		} catch (IOException e) {
			throw new CouldNotProcessRecordException("could not read line: ",e);
		}
		try {
			in.close();
		} catch (IOException e) {
			throw new CouldNotProcessRecordException("could not close reader: ",e);
		}
		return lines;
	}
}
